package com.qf.dao.impl;

import com.qf.dao.UserBankCardDao;
import com.qf.model.Banktable;
import com.qf.model.UserCard;
import com.qf.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

public class UserBankCardDaoImpl implements UserBankCardDao {
    private QueryRunner queryRunner = new QueryRunner(DruidUtils.getDataSource());
    //查询银行卡
    @Override
    public UserCard findUserBankCard(String cid) {
        String sql = "select * from usercard where cid = ?";
        try {
            UserCard query = queryRunner.query(sql, new BeanHandler<>(UserCard.class), cid);
            return query;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
    //修改银行卡余额
    @Override
    public int updateMoney(UserCard userCard) {
        String sql = "update usercard set Money= ? where cid =?";
        try {
            int update = queryRunner.update(sql, userCard.getMoney(), userCard.getCid());
            return update;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }
        //通过银行卡号查询银行存款信息
    @Override
    public Banktable findDepositByCid(Banktable banktable) {
        String sql = "select * from banktable where cid =?";
        try {
            Banktable query = queryRunner.query(sql, new BeanHandler<>(Banktable.class), banktable.getCid());
            return query;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
